package com.pet.server.ext.action.article;

import com.pet.server.ext.ActionBase;
import com.pet.server.ext.ApiError;
import com.pet.server.ext.Result;
import com.pet.server.ext.data.Article;
import com.pet.server.ext.data.UserArticle;
import com.pet.server.ext.service.ArticleService;
import com.pet.server.ext.util.NumberUtil;
import com.pet.server.ext.util.Parameters;
import com.pet.server.ext.util.StringUtil;

public class Focus extends ActionBase{

	public Integer article_id;
	
	public Focus(){
		 needCheckAuth =true;
	}
	
	@Override
	public void initParameters(Parameters params) throws ApiError {
		article_id = NumberUtil.getInteger(params.getFieldValue("article_id"));
		if(StringUtil.isEmpty(article_id)){
			throw ApiError.Type.INVALID_PARAM.toException();
		}
	}
	
	@Override
	public Result invokeService() throws ApiError {
		ArticleService articleService = new ArticleService();
		Article aritcle = articleService.findArticle(article_id);
		if(null==aritcle){
			throw ApiError.Type.LOGIC_ERROR.toException("文章信息不存在!");
		}
		UserArticle ua = new UserArticle();
		ua.article_id=article_id;
		ua.user_id=user.user_id;
		articleService.saveUserArticle(ua);
		Result result = new Result();
        data.put("message", "添加收藏成功!");
        result.put("data", data);
	    return result;
	}


}
